The Java 2 Platform, Enterprise Edition (J2EE) is an open and standard based platform for developing, deploying and managing n-tier, Web-enabled, server-centric, and component-based enterprise applications. Within this environment there are three types of enterprise java beans (EJB): entity beans, session beans, and message-driven beans.
Of particular interest are entity beans which are used to implement a complex business entity. An entity bean models a business entity or models multiple actions within a business process. Entity beans are often used to facilitate business services that involve data and computations on that data. For example, an application developer might implement an entity bean to retrieve and perform computation on items within a purchase order. The entity bean can manage multiple, dependent, persistent objects in performing its necessary tasks.
Thus, an entity bean is typically characterized as a remote object that manages persistent data, performs complex business logic, potentially uses several dependent Java objects, and can be uniquely identified by a primary key. Entity beans are normally considered coarse-grained persistent objects, because they utilize persistent data stored within several fine-grained persistent Java objects.
Entity beans are persistent because they are capable of surviving a server crash or a network failure. When an entity bean is re-instantiated, the states of previous instances are automatically restored.
Each entity bean has a persistent identity associated with it. That is, the entity bean contains a unique identity that can be retrieved if one has the primary key—given the primary key, a client can retrieve the entity bean. If the bean is not available, the container instantiates the bean and repopulates the persistent data.
The persistence for entity bean data is provided both for saving state when the bean is passivated and for recovering the state when a failover has occurred. Entity beans are able to survive because the data is stored persistently by the container in some form of data storage system, such as a database. Entity beans persist business data using one of the two following methods: a) Automatically by the container using a container-managed persistent (CMP) entity bean, or b) Programmatically through methods implemented in a bean-managed persistent (BMP) entity bean. These methods use JDBC or SQLJ to manage persistence in a relational database; or use any API to manage persistent data in non-relational store.
While there are various trade-offs when determining how to manage persistence for an EJB, one of these trade-offs involves how to manage EJB references to data sources. For example, an EJB may retrieve different fields of data from various tables of a database. Within the coding of the EJB application, the code specifies the identity of this database or data source.
A BMP EJB can connect to multiple data sources by defining within itself multiple data sources and then looking up these data sources during run time. However, in contrast, during deployment, a CMP EJB can only specify one data source in the persistence data that is managed for it. Thus, for a CMP EJB to connect to multiple, different databases, the CMP EJB must be deployed for each different database and bound to one data source at a given runtime. Multiple deployments of a CMP EJB add to the complexity of the application server environment and unnecessarily utilize resources within this environment. Thus, there remains the need within current J2EE Applications for a manner of enabling one deployment of a CMP EJB to access multiple data sources.